package com.nstar.helloworld.view
{
	import mx.containers.VBox;
	import mx.events.FlexEvent;
	import com.nstar.base.controls.Header;
	import mx.controls.LinkButton;
	import flash.events.MouseEvent;
	import com.nstar.helloworld.mxml.LoginView;
	import mx.managers.PopUpManager;
	import flash.display.DisplayObject;
	import mx.core.Application;
	import mx.containers.Form;
	import com.nstar.base.controls.ButtonAssets;
	import mx.events.EffectEvent;
	import com.nstar.helloworld.mxml.RegisterView;
	import com.adobe.ac.mxeffects.Flip;
	import com.adobe.ac.mxeffects.DistortionConstants;
	import flash.events.Event;
	import mx.controls.CheckBox;
	import com.nstar.helloworld.model.Model;
	import com.nstar.base.util.Logger;

	public class WelcomeClass extends VBox
	{
		public var header:Header;
		public var loginView:LoginView;
		public var registerView:RegisterView;
		
		public var chkDebug:CheckBox;
		
		var model:Model = Model.getInstance();
		var logger:Logger = Logger.getInstance();
		
		public function WelcomeClass()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		function init(event:FlexEvent):void{
			loginView.addEventListener(Event.CHANGE,flipToRegistration);
			loginView.addEventListener(Event.SELECT,selectHandler);
			registerView.addEventListener(Event.CHANGE,flipToLogin);
			chkDebug.addEventListener(MouseEvent.CLICK,debugHandler);
		}
		
		function selectHandler(event:Event):void{
			this.dispatchEvent( new Event( Event.SELECT) )
		}
		
		private function flipToRegistration(event:Event) : void
		{
			var e : Flip = new Flip( loginView );
			e.siblings = [ registerView ];
			e.direction = DistortionConstants.RIGHT;
			e.duration = 500;
			e.play();
		}
		
		private function flipToLogin(event:Event) : void
		{
			var e : Flip = new Flip( registerView );
			e.siblings = [ loginView ];
			e.direction = DistortionConstants.LEFT;					
			e.duration = 500;
			e.play();
		}		
		
		function debugHandler(event:MouseEvent):void{
			model.isDebug = chkDebug.selected;
		}

	}
}